<template>
  <div>
    <dami-dialog @confirm="confirm" @cancel="cancel">
      <el-form :inline="false" class="demo-form-inline">
        <el-form-item label="商品类别">
          <el-select v-model="options.CategoryId" placeholder="请选择">
            <el-option
              v-for="item in CategoryList"
              :key="item.Id"
              :label="item.Name"
              :value="item.Id">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="标题">
          <el-input v-model="options.Title" placeholder="标题"></el-input>
        </el-form-item>
        <el-form-item label="副标题">
          <el-input v-model="options.SubTitle" placeholder="副标题"></el-input>
        </el-form-item>
        <el-form-item label="市场均价">
          <el-input v-model="options.AveragePrice" placeholder="市场均价"></el-input>
        </el-form-item>
        <el-form-item label="价格">
          <el-input v-model="options.Price" placeholder="价格"></el-input>
        </el-form-item>
        <el-form-item label="活动价格">
          <el-input v-model="options.ActivityPrice" placeholder="活动价格"></el-input>
        </el-form-item>
        <el-form-item label="商品详情描述">
          <el-input v-model="options.DetailText" placeholder="商品详情描述"></el-input>
        </el-form-item>
      </el-form>
    </dami-dialog>
  </div>
</template>

<script type="text/javascript">
import SYS_Category_sel from  '../../../API/SYS_Category_sel.js';
import SYS_Product_update from  '../../../API/SYS_Product_update.js';
import SYS_Product_single from  '../../../API/SYS_Product_single.js';

  export default {
    data(){
      return {
        CategoryList:[],
        options:{
          StoreId:'9F1DFD1D-7BF3-479E-8C35-01A59D1AB167',
          CategoryId:'',
          Title:'',//标题
          SubTitle:'',//副标题
          AveragePrice:'',//市场均价
          Price:'',//价格
          ActivityPrice:'',//活动价格
          DetailText:'',//商品详情描述
        }
      }
    },
    props:['edit-id','view-state'],
    mounted:function(){
      this.getCategoryList();
      this.getProMes();
    },
    watch:{
      viewState(val){
        if(!!val){
          this.getProMes();
        }
      }
    },
    methods:{
      getCategoryList(){
        SYS_Category_sel({}).then((data,total) => {
          this.CategoryList = data;
        }).catch(message => {
          this.$Message({
              message
          });
        });
      },
      getProMes(){
        if(!this.editId){
          this.$Message({
              message:"请传递商品ID"
          });
          return;
        }
        SYS_Product_single({Id:this.editId}).then(data => {
          this.options.CategoryId = data.CategoryId;
          this.options.Title = data.Title;
          this.options.SubTitle = data.SubTitle;
          this.options.AveragePrice = data.AveragePrice;
          this.options.Price = data.Price;
          this.options.ActivityPrice = data.ActivityPrice;
          this.options.DetailText = data.DetailText;
        }).catch(message => {
          this.$Message({
              message
          });
        });
      },
      confirm(){
        let parm = {};
        parm.Id = this.editId;
        Object.assign(parm,this.options);

        SYS_Product_update(parm).then(data => {
          this.$Message({
              message:"操作成功"
          });
          this.$emit("confirm");
        }).catch(message => {
          this.$Message({
              message
          });
        });
      },
      cancel(){
        this.$emit("cancel");
      }
    }
  }
</script>
